package com.application.mylibrary.base.mvp;

import android.os.Bundle;

import com.application.mylibrary.base.BaseActivity;

/**
 * Created by lixuce on 2019/8/7.
 */
public abstract class BaseMvpActivity<V extends IBaseView, P extends IBasePresenter<V>> extends BaseActivity {
    private V view;
    private P presenter;

    public abstract V createView();

    public abstract P createPresenter();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (presenter == null)
            presenter = createPresenter();
        if (view == null)
            view = createView();
        if (view != null && presenter != null) {
            this.presenter.attachView(view);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (presenter != null) {
            this.presenter.detachView();
            this.presenter = null;
        }
    }

    public P getPresenter() {
        return presenter;
    }
}
